<template>
<div style="height:100%">
  <div class="prdlist">
  <el-form ref="form" :model="form" label-width="80px">

  <el-form-item label="客户类型">
    <el-radio-group v-model="form.customertype">
      <el-radio  :label="2"  >企业</el-radio>
      <el-radio :label="1" >个人</el-radio>
    </el-radio-group>
  </el-form-item>
    <el-form-item label="客户名称">
    <el-input v-model="form.companyname" ></el-input>
  </el-form-item>
      <el-form-item label="联系人">
    <el-input v-model="form.username" ></el-input>
  </el-form-item>
    
   <el-form-item label="联系电话">
    <el-input v-model="form.phone" ></el-input>
  </el-form-item>
  <el-form-item label="所在地区">
<el-cascader
ref="cc"
      size="large"
      :options="options"
      v-model="selectedOptions"
      @change="handleChange">
    </el-cascader>
  </el-form-item>
     <el-form-item label="联系地址">
    <el-input v-model="form.addr2" ></el-input>
  </el-form-item>
  <el-form-item label="备注">
    <el-input type="textarea" v-model="form.comment"></el-input>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="addmember">新建</el-button>
  </el-form-item>
</el-form>
  <div>

  </div>
  </div>
</div>
</template>
<script>
import { addmember} from '@/api/policy'


import { regionData } from 'element-china-area-data'
  export default {
    name:'addcustomer',
    data() {
      return {
        options: regionData,
        selectedOptions: [],
        workarea:'',
        form: {
          username: '极乐空间',
          companyname:'',
          region: '',
          date1: '',
          date2: '',
          delivery: false,
          type: 2,
          customertype: '',
          comment: '',
          addr:'',
          addrcode:'',
          addr2:'',
          phone:'',
        }
      }
    },
  mounted(){
    console.log(this.options)
  },
    methods: {
      addmember(){
        if(!this.form.customertype)
        {
          this.$toast('未选择客户类型')
          return;
        }
         if(!this.form.companyname)
        {
          this.$toast('客户名称未输入')
          return;
        }
                 if(!this.form.username)
        {
          this.$toast('联系人未输入')
          return;
        }
      if(!this.form.phone)
        {
          this.$toast('电话未输入')
          return;
        }
      if(!this.form.addr)
        {
          this.$toast('所在地区未输入')
          return;
        }
              if(!this.form.addr2)
        {
          this.$toast('联系地址未输入')
          return;
        }
          this.$loadingshow();
       addmember(this.form).then(res => {
         this.$loadingclose();
        if (res.code == 200) {
             this.$toast('添加成功')
             location.reload();
           //   document.getElementsByClassName('el-table__body-wrapper')[0].style.height='auto';
        } 
        else{
          this.$toast(res.message)
        }
      });



      },
      handleChange(){
   console.log( this.selectedOptions);
   this.$nextTick(function(){

     var dts=this.$refs.cc.getCheckedNodes();
 this.form.addr=dts[0].parent.parent.label+dts[0].parent.label+dts[0].label;
 this.form.addrcode=JSON.stringify(this.selectedOptions);
   })

      },
      onSubmit() {
        console.log('submit!');
      }
    }
  }
</script>

<style lang="scss" scoped>
.prdlist{
  width:90%;
  height: 100%;
  margin: 2%;
}

</style>
